﻿@page "{userId}"
@model DotNetStar.TheKing.Web.Pages.IndexModel

@{
    ViewBag.Title = $"{Model.CurrentUser.UserName}的空间";
}
<div class="row">
    <div class="col-md-4">
        @await Component.InvokeAsync("UserPanel", Model.CurrentUser.Id)
        <div class="mt-3 mb-3 border bg-light">
            <div class="border-bottom m-3"><b>TA 的阅读排行</b></div>
            <div class="col">
                @Html.Partial("/Pages/Content/_ListUnstyled.cshtml", Model.UserHotContents)
            </div>
        </div>
    </div>
    <div class="col-md-8">
        <div class="row mt-5">
            <div class="col-12">
                <h1><b>@ViewBag.Title</b></h1>
            </div>
        </div>
        <div class="mt-3">
            <ul class="list-group list-group-flush">
                @if (!Model.Contents.Items.Any())
                {
                    <li class="list-group-item text-center">
                        还没有任何数据！
                    </li>
                }
                @foreach (var item in Model.Contents.Items)
                {
                    <li class="list-group-item">
                        <h5>
                            @if (!item.IsAsk)
                            {
                                @if (item.IsVideo)
                                {
                                    <span title="多媒体视频" class="badge badge-info">视</span>
                                }
                                @if (item.IsOriginal)
                                {
                                    <span title="原创内容" class="badge badge-success">原</span>
                                }

                                @if (!item.IsFree())
                                {
                                    <span title="需要支付" class="badge badge-danger">售</span>
                                }
                                @if (item.IsSecret)
                                {
                                    <span title="私密帖子" class="badge badge-primary">私</span>
                                }
                                @if (item.Status == ContentStatus.Draft)
                                {
                                    <span title="草稿" class="badge badge-secondary">稿</span>
                                }
                            }
                            else
                            {
                                <span title="问答" class="badge badge-warning">问</span>
                            }
                            <a asp-page="/Content/Detail" asp-route-id="@item.Id" target="_blank">

                                @item.Subject
                            </a>
                        </h5>
                        <div class="float-left">
                            <ul class="list-inline mt-3">
                                @if (item.Category != null)
        {
                        <li class="list-inline-item">
                            <a asp-page="/Content/Index" asp-route-categoryId="@item.Category.Id" class="text-primary text-sm">                               
                                @item.Category.Name
                            </a>
                        </li>
}
                                <li class="list-inline-item text-sm text-muted d-sm-block d-md-none" title="阅读量"><i class="fa fa-eye"></i> @item.VisitNum</li>
                                <li class="list-inline-item text-sm text-muted" title="评论数"><i class="far fa-comments"></i> @item.CommentCount</li>
                                <li class="list-inline-item text-sm text-muted" title="点攒数"><i class="far fa-thumbs-up"></i> @item.LikeNum</li>
                                <li class="list-inline-item text-sm text-muted" title="日期"><i class="far fa-calendar-alt"></i> @item.PostedTime.ToHumanDateTimeString()</li>

                            </ul>
                        </div>
                        <div class="float-right">
                            @if (User.Identity.UserId() == item.AuthorId)
                            {
                            <ul class="list-inline text-sm text-muted">
                                <li class="list-inline-item"><a asp-page="/Content/Edit" asp-route-id="@item.Id"><i class="fa fa-pencil-alt"></i> 编辑</a></li>
                                <li class="list-inline-item"><a href="javascript:removeContent('@item.Id')"><i class="fa fa-trash-alt"></i> 删除</a></li>
                            </ul>
                            }
                        </div>
                        <div class="clearfix"></div>
                    </li>
                }
            </ul>

            <div class="mt-3">
                @Html.Pagination(Model.Contents)
            </div>
        </div>
    </div>

</div>
@if (User.Identity.UserId() == Model.CurrentUser.Id)
{
    @section scripts{ 
        <script type="text/javascript">
         /**
         * 删除帖子
         * @@param id 帖子Id
         */
        function removeContent(id) {
              bootbox.confirm('删除后将不可操作，确定吗？', function (result) {
                  if (result) {
                      $.post('/c/' + id + '?handler=Delete', { contentId: id },
                        function (data) {
                            bootbox.alert('帖子已被删除', function () {
                                location.reload();
                            });
                        })
                }
            })
        }
        </script>
    }

}